<script type="text/javascript">

	 //选择经销商-经销商
	 function chooseSupplier(single=1,is_customer=0) {
	 	if(is_customer==1){
	 		var customer_title="选择客户";
	 		var customer_title1="请选择客户";
	 	}else{
	 		var customer_title="选择经销商";
	 		var customer_title1="请选择经销商";
	 	}

	    layer.open({
	      type: 2,
	      title: customer_title,
	      shadeClose: true,
	      shade: 0.3,
	      maxmin: false, //开启最大化最小化按钮
	      area: ['775px', '510px'],
	      fixed: false, //不固定
	      btn: ['确定', '取消'],
	      content: "/admin/basic/choose_customer.html?single="+single+"&is_customer="+is_customer,//单选1，客户1,多选0，经销商0
	      btn1: function (index, layero) {
	            var body = layer.getChildFrame('body', index);
	            if(single==1){
	            	var id =  body.find("#grid").jqGrid('getGridParam','selrow');
		            if (id == '' || id == null) {
		              layer.msg(customer_title1);
		              return false;
		            } else {
		              //获取商品信息
		              $.get("/admin/basic/one_customer.html", { id: id }, function (data, state) {
		                if (data.status == 1) {
		                  	$("#customer input").val(data.info.sn + " " + data.info.name);
		                  	$('#customerid').val(data.info.id);
		                  	$("#addr").val(data.info.name + " " + data.info.name);
		                  	layer.close(index);
		                } else {
		                  layer.msg("获取信息失败");
		                }
		              })
		            }

	            }else{
	            	var ids =  body.find("#grid").jqGrid('getGridParam','selarrrow');
		            if (ids == '' || ids == null) {
		              layer.msg(customer_title1);
		              return false;
		            } else {
		              //获取商品信息
		              $.get("/admin/basic/one_customer.html", { id: ids }, function (data, state) {
		                if (data.status == 1) {
		                  	$("#customer input").val(data.info.names);
		                  	$('#customerid').val(data.info.ids);
		                  	layer.close(index);
		                } else {
		                  layer.msg("获取信息失败");
		                }
		              })
		            }

	            }
	            
	            layer.close(index);
	            return false;
	      },
	      btn4: function (index, layero) {
	        layer.close(index);
	        return false;
	      }
	    })
	 }



	//选择源单-收款单
	function chooseSource_order(url, obj,callback) {
		var o = $(obj);
		var chooseSource_order_garr = new Array();
		chooseSource_order_garr['status'] = 0;
		layer.open({
			type: 2,
			title: "选择源单",
			shadeClose: true,
			shade: 0.3,
          	maxmin: true, //开启最大化最小化按钮
          	area: ['775px', '580px'],
          	fixed: false, //不固定
          	btn: ['确定', '取消'],
          	content: url,
          	btn1: function (index, layero) {
          		var body = layer.getChildFrame('body', index);
	  			//判断是否至少有一个选中
				if(body.find('.cbox').is(':checked')) {
					var ids = [];
					body.find("#grid input:checkbox[name='checkboxname']:checked").each(function(i){
					   ids.push($(this).val());
					   //checkedTitles.push($(this).attr("title"));
					});
					//console.log(ids);
					
					$.get("/admin/basic/one_order.html", { id: ids}, function (data, state) {
						//console.log(data);
			            if (data.status == 1) {
						    chooseSource_order_garr['btn'] = 1;
						    chooseSource_order_garr['status'] = 1;
						    chooseSource_order_garr['data'] = data;
				            callback(chooseSource_order_garr);
				            layer.close(index);
				        } 
		        	})
				}else{
					//chooseSource_order_garr['status'] = 2;
					//callback(chooseSource_order_garr);
					layer.msg("请选择需要操作的数据");
	         		return false;
				}
        	},
        	btn2: function (index, layero) {
        		layer.close(index);
	        	return false;
        	}
        	
    	});
	}
	//数据表格保存按钮
	function save_jqgrid(edit_row_id,edit_col_id,tablename,callback){
		//先保存
        if (edit_row_id != 0 && edit_col_id != 0) {
          tablename.jqGrid("saveCell", edit_row_id, edit_col_id);
          edit_row_id = 0;
          edit_col_id = 0;
        }
        tablename.saveRow();
       	if (typeof(callback) != "undefined") {
             callback(tablename);
        }
	}

	 //新增行
    function add_row($id){
      
        var ids = $("#grid").jqGrid('getDataIDs');
        //获得当前最大行号（数据编号）
        var rowid = Math.max.apply(Math,ids);
        //获得新添加行的行号（数据编号）
        newrowid = rowid+1;
        obj = {id:newrowid};
        jQuery("#grid").jqGrid('addRowData',newrowid, obj,'after',$id);
        //console.log(ids);
    }
    //新增行
    function del_row($id){
        $("#grid").jqGrid("delRowData", $id);
    }

    //选择源单-核销单
	function chooseSourcePayList_order(url, obj,callback) {
		var o = $(obj);
		var chooseSource_order_garr = new Array();
		chooseSource_order_garr['status'] = 0;
		layer.open({
			type: 2,
			title: "选择源单",
			shadeClose: true,
			shade: 0.3,
          	maxmin: true, //开启最大化最小化按钮
          	area: ['775px', '580px'],
          	fixed: false, //不固定
          	btn: ['确定', '取消'],
          	content: url,
          	btn1: function (index, layero) {
          		var body = layer.getChildFrame('body', index);
          		//获取所有选中行
				var ids =  body.find("#grid").jqGrid('getGridParam','selarrrow');
				//console.log(ids);

				if (ids == '' || ids == null) {
					layer.msg("请选择需要操作的数据");
					return false;
				} else {
					//获取信息
					$.get("/admin/basic/one_payment.html", { ids: ids }, function (data, state) {
						//console.log(data);
			            if (data.status == 1) {
						    chooseSource_order_garr['btn'] = 1;
						    chooseSource_order_garr['status'] = 1;
						    chooseSource_order_garr['data'] = data;
				            callback(chooseSource_order_garr);
				            layer.close(index);
				        } 
					})
				}
	  			// 		//判断是否至少有一个选中
				// if(body.find('.cbox').is(':checked')) {
				// 	var ids = [];
				// 	body.find("#grid input:checkbox[name='checkboxname']:checked").each(function(i){
				// 	   ids.push($(this).val());
				// 	   //checkedTitles.push($(this).attr("title"));
				// 	});
				// 	//console.log(ids);
					
				// 	$.get("/admin/basic/one_order.html", { id: ids}, function (data, state) {
				// 		//console.log(data);
			 //            if (data.status == 1) {
				// 		    chooseSource_order_garr['btn'] = 1;
				// 		    chooseSource_order_garr['status'] = 1;
				// 		    chooseSource_order_garr['data'] = data;
				//             callback(chooseSource_order_garr);
				//             layer.close(index);
				//         } 
		  //       	})
				// }else{
				// 	//chooseSource_order_garr['status'] = 2;
				// 	//callback(chooseSource_order_garr);
				// 	layer.msg("请选择需要操作的数据");
	   //       		return false;
				// }
        	},
        	btn2: function (index, layero) {
        		layer.close(index);
	        	return false;
        	}
        	
    	});
	}
	
</script>
	